package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zko {
   static void a(Cells var0, int var1, int var2, int var3, int var4, AutoFitterOptions var5) throws Exception {
      if (var2 - var1 > 2) {
         var0.d = new zkt(var0, 16383);

         try {
            b(var0, var1, var2, var3, var4, var5);
         } finally {
            var0.m();
         }
      } else {
         b(var0, var1, var2, var3, var4, var5);
      }

   }

   private static int a(WorksheetCollection var0, zfv var1, Style var2, String var3, boolean var4) throws Exception {
      ArrayList var5 = null;
      if (var1.c == 4) {
         zayy var6 = (zayy)var1.d;
         if (var6.f()) {
            zbap var7 = (zbap)var6;
            var5 = var7.a(var0, var3.length(), var2.getFont());
         }
      }

      if (var5 == null) {
         var5 = new ArrayList();
         FontSetting var18 = new FontSetting(0, var3.length(), var0, false);
         var18.c = var2.q();
         com.aspose.cells.b.a.a.ze.a(var5, (Object)var18);
      }

      int var19 = 0;
      int var20 = 0;
      int var8 = 0;
      Iterator var9 = var5.iterator();

      while(var9.hasNext()) {
         FontSetting var10 = (FontSetting)var9.next();
         int var11 = 0;
         float var12 = 10.0F;
         String var13 = "Arial";
         Font var14 = var10.c;
         if (var14 != null) {
            if (var14.isBold()) {
               var11 |= 1;
            }

            if (var14.isItalic()) {
               var11 |= 2;
            }

            if (var14.isStrikeout()) {
               var11 |= 8;
            }

            if (var14.getUnderline() != 0) {
               var11 |= 4;
            }

            var13 = var2.e().n().a(var14.getName());
            var12 = (float)var14.getDoubleSize();
         }

         com.aspose.cells.a.d.zfq var15 = com.aspose.cells.a.d.zfs.b(var13, var11, false);
         var8 = zamb.a(var13, var12, var11);
         String var16 = var3;
         if (var5.size() > 0) {
            var16 = var3.substring(var10.getStartIndex(), var10.getStartIndex() + var10.getLength());
         }

         for(int var17 = 0; var17 < var16.length(); ++var17) {
            var19 += (int)var15.b(var16.charAt(var17), var12);
         }

         if (var2.getRotationAngle() != 0 && var2.getRotationAngle() != 255) {
            var20 = com.aspose.cells.a.d.zfq.a(var13, var12, "|", var11).c();
         }
      }

      if (var2.getRotationAngle() != 0 && var2.getRotationAngle() != 255) {
         int var22 = Math.abs(var2.getRotationAngle());
         if (var22 == 90) {
            return var20;
         } else {
            double var23 = 3.141592653589793D * (double)Math.abs(var2.getRotationAngle()) / 180.0D;
            var19 = (int)((double)var19 * Math.cos(var23) + (double)var20 * Math.sin(var23) + 6.5D);
            return var19 + var8 * 4 + 1;
         }
      } else if (var4) {
         byte var21 = 18;
         switch(var2.getHorizontalAlignment()) {
         case 1:
            return var19 + var8 * 4 + 1 + var21 * 2;
         default:
            return var19 + var8 * 4 + 1 + var21;
         }
      } else {
         return var19 + var8 * 4 + 1;
      }
   }

   private static int a(zbg var0) throws Exception {
      int var1 = 0;

      for(int var2 = 0; var2 < var0.d.size(); ++var2) {
         String var3 = (String)var0.d.get(var2);
         com.aspose.cells.a.d.zfq var4 = com.aspose.cells.a.d.zfs.b(var0.a, var0.c, false);
         int var5 = zamb.a(var0.a, var0.b, var0.c);
         int var6 = var5 * 4 + 1;
         float var7 = 0.0F;

         for(int var8 = 0; var8 < var3.length(); ++var8) {
            var7 += var4.b(var3.charAt(var8), var0.b);
         }

         var6 += (int)((double)var7 + 0.5D);
         if (var1 < var6) {
            var1 = var6;
         }
      }

      return var1;
   }

   private static boolean a(Cells var0, int var1, int var2) {
      if (var0.h().hasAutofilter()) {
         CellArea var3 = var0.h().getAutoFilter().h();
         if (var1 == var3.StartRow && var2 >= var3.StartColumn && var2 <= var3.EndColumn) {
            return true;
         }
      }

      if (var0.h().getListObjects().getCount() > 0) {
         return var0.h().getListObjects().f(var1, var2);
      } else {
         return var0.h().getPivotTables().getCount() > 0 ? var0.h().getPivotTables().b(var1, var2) : false;
      }
   }

   private static void b(Cells var0, int var1, int var2, int var3, int var4, AutoFitterOptions var5) throws Exception {
      WorksheetCollection var6 = var0.r();
      Style var7 = var0.r().D();
      HashMap var8 = new HashMap();
      if (var5 != null) {
         for(int var9 = 0; var9 < var0.getColumns().getCount(); ++var9) {
            Column var10 = var0.getColumns().getColumnByIndex(var9);
            if (var10.getIndex() >= var3 && var10.getIndex() <= var4 && var5.getIgnoreHidden() && var10.isHidden()) {
               var8.put(var10.getIndex(), true);
            }
         }
      }

      HashMap var30 = new HashMap();
      HashMap var31 = new HashMap();
      zr var11 = var0.f();
      zahr var12 = var0.getRows().a.a(var1, var2, false);
      zfv var13 = new zfv();
      zfv var14 = var13;
      int var20 = 0;

      while(true) {
         int var19;
         Style var22;
         String var23;
         ArrayList var34;
         label211:
         do {
            while(true) {
               label199:
               while(true) {
                  zp var15;
                  zahl var16;
                  int var25;
                  int var26;
                  int var33;
                  do {
                     if (!var12.hasNext()) {
                        com.aspose.cells.b.a.a.zc var32 = com.aspose.cells.b.a.a.zf.a(var31);

                        while(var32.c()) {
                           var34 = (ArrayList)var32.b();
                           var25 = (Integer)var32.a();
                           var26 = 0;

                           int var27;
                           for(var27 = 0; var27 < var34.size(); ++var27) {
                              zbg var28 = (zbg)var34.get(var27);
                              int var29 = a(var28);
                              if (var26 < var29) {
                                 var26 = var29;
                              }
                           }

                           var27 = (Integer)var30.get(var25);
                           if (var26 > var27) {
                              var30.put(var25, var26);
                           }
                        }

                        var32 = com.aspose.cells.b.a.a.zf.a(var30);
                        var33 = var0.r().n().k() ? 1048575 : '\uffff';
                        boolean var10000;
                        if (var1 == 0 && var2 == var33) {
                           var10000 = true;
                        } else {
                           var10000 = false;
                        }

                        while(var32.c()) {
                           var26 = (Integer)var32.b();
                           if (var26 != 0) {
                              var0.setColumnWidthPixel((Integer)var32.a(), var26);
                           }
                        }

                        return;
                     }

                     var15 = var12.e();
                     var16 = var15.b(var3, var4, false);
                  } while(var16 == null);

                  int var17 = var15.h();
                  var19 = Row.e(var15);
                  boolean var21 = true;
                  var22 = null;

                  while(true) {
                     while(true) {
                        if (var21) {
                           var20 = var16.a();
                           if (var20 < 0) {
                              continue label199;
                           }

                           var14 = var15.a(var20, var13, 7);
                        }

                        short var18 = var14.a;
                        if (var8.get(Integer.valueOf(var18)) != null) {
                           var21 = true;
                        } else if (b(var0, var17, var18)) {
                           var21 = true;
                        } else {
                           if (var21) {
                              var22 = Cell.b(var0, var19, var14);
                           } else {
                              var21 = true;
                           }

                           if (var30.get(Integer.valueOf(var18)) == null) {
                              var30.put(Integer.valueOf(var18), 0);
                           }

                           var23 = Cell.a(var0, (Style)var22, var14, 1, false);
                           if (var23 != null && !"".equals(var23)) {
                              if (!a(var0, var17, var18)) {
                                 if (var22.getRotationAngle() != 0 && var22.getRotationAngle() != 255) {
                                    var33 = a(var6, var14, var22, var23, false);
                                    var25 = (Integer)var30.get(Integer.valueOf(var18));
                                    if (var25 < var33) {
                                       var30.put(Integer.valueOf(var18), var33);
                                    }
                                 } else {
                                    var34 = (ArrayList)var31.get(Integer.valueOf(var18));
                                    if (var34 == null) {
                                       var34 = new ArrayList();
                                       var31.put(Integer.valueOf(var18), var34);
                                    }

                                    if (var22.getHorizontalAlignment() == 2) {
                                       if (var18 == var4) {
                                          var20 = var15.a(var20, false);
                                          if (var20 > -1) {
                                             var14 = var15.a(var20, var13, 7);
                                             if (var14.a == var18 + 1) {
                                                continue label211;
                                             }
                                          }

                                          if (var0.r().g(Cell.a(var0, var19, var18 + 1)).getHorizontalAlignment() != 2) {
                                             a(var34, var22, var23);
                                          }
                                          continue label199;
                                       }

                                       var20 = var16.a();
                                       if (var20 < 0) {
                                          if (var0.r().g(Cell.a(var0, var19, var18 + 1)).getHorizontalAlignment() != 2) {
                                             a(var34, var22, var23);
                                          }
                                          continue label199;
                                       }

                                       var14 = var15.a(var20, var13, 7);
                                       if (var14.a == var18 + 1) {
                                          if (var14.c == 0) {
                                             Style var35 = Cell.b(var0, var19, var14);
                                             if (var22.getHorizontalAlignment() != 2) {
                                                a(var34, var22, var23);
                                                var22 = var35;
                                                var21 = false;
                                             }
                                             continue;
                                          }

                                          a(var34, var22, var23);
                                       } else if (var0.r().g(Cell.a(var0, var19, var18 + 1)).getHorizontalAlignment() != 2) {
                                          a(var34, var22, var23);
                                       }

                                       var21 = false;
                                       var22 = Cell.b(var0, var19, var14);
                                    } else if (var14.c()) {
                                       var25 = a(var6, var14, var22, var23, false);
                                       var26 = (Integer)var30.get(Integer.valueOf(var18));
                                       if (var26 < var25) {
                                          var30.put(Integer.valueOf(var18), var25);
                                       }
                                    } else {
                                       a(var34, var22, var23);
                                    }
                                 }
                              } else {
                                 if (var22.isTextWrapped()) {
                                    String[] var24 = com.aspose.cells.b.a.zv.d(var23, '\n');
                                    if (var24.length > 1) {
                                       var23 = var24[0] == null ? "" : var24[0];

                                       for(var25 = 1; var25 < var24.length; ++var25) {
                                          if (var24[var25] != null && var24[var25].length() > var23.length()) {
                                             var23 = var24[var25];
                                          }
                                       }
                                    }
                                 }

                                 var33 = a(var6, var14, var22, var23, true);
                                 var25 = (Integer)var30.get(Integer.valueOf(var18));
                                 if (var25 < var33) {
                                    var30.put(Integer.valueOf(var18), var33);
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         } while(var14.c == 0 && Cell.b(var0, var19, var14).getHorizontalAlignment() == 2);

         a(var34, var22, var23);
      }
   }

   private static void a(ArrayList var0, Style var1, String var2) {
      int var3 = 0;
      float var4 = 10.0F;
      String var5 = "Arial";
      if (var1.q() != null) {
         Font var6 = var1.q();
         if (var6.isBold()) {
            var3 |= 1;
         }

         if (var6.isItalic()) {
            var3 |= 2;
         }

         if (var6.isStrikeout()) {
            var3 |= 8;
         }

         if (var6.getUnderline() != 0) {
            var3 |= 4;
         }

         var5 = var6.getName();
         var4 = (float)var6.getDoubleSize();
      }

      if (var1.isTextWrapped()) {
         String[] var10 = com.aspose.cells.b.a.zv.d(var2, '\n');
         if (var10.length > 1) {
            var2 = var10[0] == null ? "" : var10[0];

            for(int var7 = 1; var7 < var10.length; ++var7) {
               if (var10[var7] != null && var10[var7].length() > var2.length()) {
                  var2 = var10[var7];
               }
            }
         }
      }

      for(int var11 = 0; var11 < var0.size(); ++var11) {
         zbg var13 = (zbg)var0.get(var11);
         if (com.aspose.cells.b.a.zv.b(var13.a, var5) && var13.c == var3 && (int)var13.b == (int)var4) {
            for(int var8 = 0; var8 < var13.d.size(); ++var8) {
               String var9 = (String)var13.d.get(var8);
               if (com.aspose.cells.b.a.zv.b(var9, var2)) {
                  return;
               }

               if (var9.length() < var2.length()) {
                  var13.d.add(var8, var2);
                  if (var13.d.size() > 10) {
                     var13.d.remove(10);
                  }

                  return;
               }
            }

            if (var13.d.size() < 10) {
               com.aspose.cells.b.a.a.ze.a(var13.d, (Object)var2);
            }

            return;
         }
      }

      zbg var12 = new zbg();
      var12.a = var5;
      var12.b = var4;
      var12.c = var3;
      com.aspose.cells.b.a.a.ze.a(var12.d, (Object)var2);
      com.aspose.cells.b.a.a.ze.a(var0, (Object)var12);
   }

   private static boolean b(Cells var0, int var1, int var2) {
      for(int var3 = 0; var3 < var0.q().getCount(); ++var3) {
         CellArea var4 = var0.q().a(var3);
         if (var4.StartRow <= var1 && var4.EndRow >= var1 && var4.StartColumn <= var2 && var4.EndColumn >= var2) {
            return var4.StartColumn != var4.EndColumn;
         }
      }

      return false;
   }
}
